﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevTeam;

using System;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Depo.CekmeTesti
{
    public partial class Sonuclar : XForm
    {
        string tip = string.Empty;
        public Sonuclar(string tip)
        {
            InitializeComponent();
            this.tip = tip;
        }

        DataSet d;
        private void Sonuclar_Load(object sender, EventArgs e)
        {
            d = ExecuteDataSet("GetCekmeTestleri", tip);
            gridView1.Init(d.Tables[0]);
            gridView1.Columns["En"].ColumnEdit = gridView1.Columns["Boy"].ColumnEdit = null;
            d.Tables[1].SetPK("RollId");

            DataRelation FK1 = new DataRelation("FK1",
                d.Tables[1].Columns["RollId"],
                d.Tables[0].Columns["RollId"]);
            d.Relations.Add(FK1);

            //            gridView1.DataTable().Columns["ProductId"].Expression = "Parent(FK1).ProductId";
            gridView1.DataTable().Columns["VendorId"].Expression = "Parent(FK1).VendorId";
            gridView1.DataTable().Columns["BrandId"].Expression = "Parent(FK1).BrandId";
            gridView1.DataTable().Columns["KompozisyonId"].Expression = "Parent(FK1).KompozisyonId";
            gridView1.DataTable().Columns["Qty"].Expression = "Parent(FK1).Qty";

            gridView1.FormatAsNumber(1, "Qty");
            gridView1.AddSummary("Qty");
            gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            //gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView1.MoveLast();
            gridView1.BestFitColumns();

            gridView1.RowCellStyle += gridView1_RowCellStyle;
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.Column.FieldName == "RollId")
                e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            //gridView1.BestFitColumns();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            ExecuteNonQuery("UpdCekmeTestleri", gridView1.SerializeChanges(), WhoAmI);
            Notify("Kaydedildi");
        }
    }
}
